package com.example.administrator.familfinalcialmanagement.ui.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.databinding.ItemFuncationBinding;
import com.example.administrator.familfinalcialmanagement.util.listener.BaseRecyclerViewHolder;
import com.example.administrator.familfinalcialmanagement.util.listener.OnItemClickListener;

import java.util.List;

/**
 * Created by 86178 on 2019/12/2.
 * author mogen
 * 用心，成就一切。
 */
public class FuncationAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {
    private List<String> strings;
    private Context mcontext;
    OnItemClickListener mOnItemClickLitener;

    public FuncationAdapter(Context context, List<String> strings) {
        this.mcontext = context;
        this.strings = strings;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemFuncationBinding functionBinding = DataBindingUtil.inflate( LayoutInflater.from( mcontext ),
                R.layout.item_funcation, parent, false );
        functionBinding.setAdapter( this );
        return new TourViewHolder( functionBinding );
    }

    @Override
    public void onBindViewHolder(final BaseRecyclerViewHolder holder, final int position) {
        holder.bindData( strings.get( position ) );
        TourViewHolder tv = (TourViewHolder) holder;
        tv.tvModuleClassName.setText( strings.get( position ) );

        switch (position) {
            case 1:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.DD4C ) );
                break;
            case 2:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.ff862e ) );
                break;
            case 3:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.colorAccent ) );
                break;
            case 4:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.blue ) );
                break;
            case 5:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.DD4C ) );
                break;
            case 6:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.FE315D ) );
                break;
            case 7:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.E78FE ) );
                break;
            case 0:
                tv.tvModuleClassName.setBackgroundColor( mcontext.getResources().getColor( R.color.DD4C ) );
                break;
            default:
        }

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener( new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick( holder.itemView, pos );
                }
            } );

            holder.itemView.setOnLongClickListener( new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemLongClick( holder.itemView, pos );
                    return false;
                }
            } );
        }
    }

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    public class TourViewHolder extends BaseRecyclerViewHolder<String> {
        ItemFuncationBinding functionBinding;
        TextView tvModuleClassName;

        public TourViewHolder(ItemFuncationBinding dataBinding) {
            super( dataBinding.getRoot() );
            functionBinding = dataBinding;
            tvModuleClassName = dataBinding.tvModuleClassName;
        }

        @Override
        public void bindData(String data) {
            functionBinding.setBean( data );
        }
    }

    @Override
    public int getItemViewType(int position) {
        return strings.size();
    }

    public void toNext(View view, String t) {

    }

}
